package com.thirteenClassicsServer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.thirteenClassics.result.Result;
import com.thirteenClassics.vo.FileUploadResponse;
import com.thirteenClassicsServer.service.impl.FileServiceImpl;


@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileServiceImpl fileService;

    //上传图片
    @PostMapping(value = "/uploadPicture", produces = "application/json;charset=UTF-8")
    public Result<FileUploadResponse> uploadPicture(@RequestParam("file") MultipartFile file,
            @RequestParam("catalogName") String catalogName,
            @RequestParam("lang") String lang,
            @RequestParam("imguploadId") Long imguploadId,
            @RequestParam("imguploadcatalogId") Long imguploadcatalogId) {
        return Result.success(fileService.uploadpic(file, catalogName, lang, imguploadId, imguploadcatalogId));
    }

    @PostMapping("/uploadJdbFile")
    public Result<FileUploadResponse> uploadJdbFile(MultipartFile file) {
        return Result.success(fileService.upload(file));
    }

    @PostMapping("/txtFile")
    public Result<String> TxtFile(MultipartFile file) {
        return Result.success(fileService.txtToString(file));
    }
}
